<? include_once("../include/session.php"); 
 include_once("../include/dbConnect.php"); ?>
<? 
if($_SERVER['REQUEST_METHOD']=="POST"){ 
	 include("profilProcess.php");
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<title>  </title>
<!-- place any meta headers below -->
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	<meta name="keywords" content="">
	<meta name="description" content="">
<!-- end meta header -->
<!-- place any scripts below -->
	<script src="../include/script/CalendarPopup.js"></script>
	<script src="../include/script/common.js"></script>
	<script src="../include/script/PointerTable.js"></script>
	<script language="JavaScript">document.write(getCalendarStyles());</script>
	<script language="javascript">
<!-- check input form (for required data/ is not null) -->
	 	 function checkForm(){
	 	 if(document.profilForm.profil_jabatan.value==""){
	 	 	 document.profilForm.profil_jabatan.focus();
	 	 	 alert(" profil_jabatan field is still empty, please fill it!");
	 	 	 return false;
	 	 }
	 	 if(document.profilForm.profil_nama.value==""){
	 	 	 document.profilForm.profil_nama.focus();
	 	 	 alert(" profil_nama field is still empty, please fill it!");
	 	 	 return false;
	 	 }
	 	 return true;
	 }
	 </script>
<!-- end scripts -->
<!-- place any stylesheets below -->
<link href="../style/common-portal.css" rel="stylesheet" type="text/css">
<!-- end stylesheets -->
</head>
<body onLoad="document.profilForm.elements[3].focus();"> 
<?
// include some function or class 
include_once("../include/session.php");
include_once("../include/dbConnect.php");
//----- end include ------
// get id as primary key 
if($_GET['id']){
	 $id=base64_decode($_GET['id']);
	 $id=str_replace($_SERVER['PHP_SELF'],"",$id);
// query for get a record 
	 $sql=mysql_query("SELECT * FROM profil WHERE profil_id='$id'");
	 if(mysql_num_rows($sql)){
// fetch record is match 
	 	 $data=mysql_fetch_array($sql);
	 	 $profil_id=$data["profil_id"];
	 	 $profil_jabatan=$data["profil_jabatan"];
	 	 $profil_nama=$data["profil_nama"];
	 	 $profil_tempatlahir=$data["profil_tempatlahir"];
	 	 $profil_tgllahir=$data["profil_tgllahir"];
	 	 $profil_alamat=$data["profil_alamat"];
	 	 $profil_email=$data["profil_email"];
	 	 $profil_homepage=$data["profil_homepage"];
	 	 $profil_ket=$data["profil_ket"];
	 	 $profil_photo=$data["profil_photo"];
	 	 $profil_status=$data["profil_status"];
	 }
}
?>
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="POST" name="profilForm"  enctype="multipart/form-data" > 
	<table width="780" border="0" class="GeneralTable" celpadding="4" cellspacing="1" >
	<tr><td colspan="2" bgcolor="#FFFFFF" align="right"><? include("../include/headerButton.php");?></td></tr>
	<tr><td class="fieldTable">ID</td><td class="fieldTable"><input type="text" name="profil_id" maxlength="12"readonly="true" value="<? echo $profil_id; ?>" ></td></tr>
	<tr><td class="fieldTable">Jabatan</td><td class="fieldTable"><input type="text" name="profil_jabatan"  value="<? echo $profil_jabatan; ?>" ></td></tr>
	<tr><td class="fieldTable">Nama</td><td class="fieldTable"><input type="text" name="profil_nama"  value="<? echo $profil_nama; ?>" ></td></tr>
	<tr><td class="fieldTable">Tempat Lahir</td><td class="fieldTable"><input type="text" name="profil_tempatlahir"  value="<? echo $profil_tempatlahir; ?>" ></td></tr>
	<tr><td class="fieldTable">Tanggal Lahir</td><td class="fieldTable"><script language="JavaScript" id=profil_tgllahir_picker>
	 var profil_tgllahir_picker= new CalendarPopup();
	 profil_tgllahir_picker.setReturnFunction("setDate");
	 function setDate(y,m,d) {
	 	 document.forms[0].profil_tgllahir.value=y+"/"+m+"/"+d;
	 }
</script>
<input type="text" name="profil_tgllahir" maxlength="19" value="<?  echo $profil_tgllahir; ?>" > <a href="#" id="profil_tgllahir_link" title="click here to pick up the date" onClick="profil_tgllahir_picker.showCalendar('profil_tgllahir_link'); return false;" ><img src="../images/@Date.gif" border="0"></a></td></tr>
	<tr><td class="fieldTable">Alamat</td><td class="fieldTable"><input type="text" name="profil_alamat"  value="<? echo $profil_alamat; ?>" ></td></tr>
	<tr><td class="fieldTable">Email</td><td class="fieldTable"><input type="text" name="profil_email"  value="<? echo $profil_email; ?>" ></td></tr>
	<tr><td class="fieldTable">Homepage</td><td class="fieldTable"><input type="text" name="profil_homepage"  value="<? echo $profil_homepage; ?>" ></td></tr>
	<tr><td class="fieldTable">Keterangan</td><td class="fieldTable"><textarea cols="50" rows="8" name="profil_ket"><? echo $profil_ket; ?></textarea></td></tr>
	<tr><td class="fieldTable">Photo</td><td class="fieldTable"><input type="file" name="profil_photo"  value="<? echo $profil_photo; ?>" ></td></tr>
	<tr><td class="fieldTable">Status</td><td class="fieldTable">
		<select name="profil_status">
		<?
			$stat = array ("Tidak Aktif","Aktif");
			for ($i=0;$i<=1;$i++)
			{
				if ($profil_status==$i)
					echo "<option selected value='$i'>".$stat[$i]."</option>";
				else 
					echo "<option value='$i'>".$stat[$i]."</option>";
			}
		?>
		</select>
	</td></tr>
	</table>
<br>
<? 
/* place any include files below */ 
include_once("../include/session.php");
include_once("../include/class/Page.class.php");
include_once("../include/class/Table.class.php");
include_once("../include/class/Search.class.php");
include_once("../include/dbConnect.php");
include_once("../include/function/functHeaderSort.php");
include_once("../include/editButton.php");
/* 
class paging for paging data list/view 
- initPaging = initialize behave of paging, there are four parameter 
  query/sql, number of data will be shown at each page (offset), max page number (don't care about this)
  and query string (piece of url) that represent current page 
*/
$page=new Paging();

 /** 
 Adding sorting function 
*/
$key=array("profil_id","profil_jabatan","profil_nama","profil_tempatlahir","profil_tgllahir","profil_alamat","profil_email","profil_homepage","profil_ket","profil_photo");
$sort_key=trim($_GET["sort"]); 
$order=$_GET["order"]=="desc"?"desc":"asc"; 
 if($sort_key!="" && count($key)>=(int)$sort_key) 
 { 
	 $sorting=$key[$sort_key]; 
} else { 
	 $sorting=$key[0]; 
} 
 $query="select * from profil order by $sorting $order ";

 /** 
 Adding Search Form 
*/
$search=new Search();
$search->initialize("profil","profil",array("profil_id"=>"profil_id","profil_jabatan"=>"profil_jabatan","profil_nama"=>"profil_nama","profil_tempatlahir"=>"profil_tempatlahir","profil_tgllahir"=>"profil_tgllahir","profil_alamat"=>"profil_alamat","profil_email"=>"profil_email","profil_homepage"=>"profil_homepage","profil_ket"=>"profil_ket","profil_photo"=>"profil_photo"));
$query=$search->getQuery($query); 

 /** 
 ------------- End Search Form ----------------
*/
$page->initPaging($query,5,5,"hal_profil");
/* 
getQuery = get query/sql after processed by class 
getFirstOffset = get first number of each page 
*/
$query_page=mysql_query($page->getQuery());
$number_page=$page->getFirstOffset();
/*
create class table 
setTableAttributes = set attribute of table as array like width, border, cellpadding, cellspacing 
setCellAttributes = set attribute of cell as array 
setDefaultCellAttributes = set default cell (row-column) attribute 
AddRow = a way to increase row number (adding new row) 
setCellColSpan = set span width of column (colspan) 
setCellContent = insert a cell with some data 
*/
$table=new Table();
/* variable of tables */
$totalColums=11;
$optColums=2;
$width=780;
$optWidth=80;
$table->setTableAttributes(array("class"=>"GeneralTable","width"=>"$width","border"=>"0","cellpadding"=>"0","cellspacing"=>"1"));
$table->setDefaultCellAttributes(array("width"=>round($width/($totalColums+$optColums)),"bgcolor"=>"white"));
/* Add row for title page */
$row=$table->AddRow();
$table->SetCellColSpan( $row, 1,($totalColums+$optColums) );
$table->SetCellAttributes( $row, 1, array("width"=>"100%","class"=>"fieldTable","height"=>"30") );
$table->SetCellContent( $row, 1, "<img src=\"../images/arrow.gif\" border=\"0\"><b> Data list of profil</b>" );
/* Add row for info page */ 
$row=$table->AddRow();
$table->SetCellColSpan( $row, 1,($totalColums+$optColums) );
$table->SetCellAttributes( $row, 1, array("align"=>"left","width"=>"100%","class"=>"fieldTable") );
$table->SetCellContent( $row, 1, $page->getInfoPage()."<br>".$page->getPaging());
/* Add row for header field page */ 
$row = $table->AddRow();
$table->SetCellAttribute( $row, 1, "width", "30" );
$table->SetCellContent($row,1,"no");
$table->SetFancyRowStyle( $row, array("bgcolor" => "white", 'style' => 'color: black',"class"=>"labelTable" ) );
/* set cell by header field from database */ 
$table->SetCellAttribute( $row, 2, "width", round((($width-$optWidth)/$totalColums)) );
$table->setCellContent($row,2,"profil_id ".header_sort(0));
$table->SetCellAttribute( $row, 3, "width", round((($width-$optWidth)/$totalColums)) );
$table->setCellContent($row,3,"profil_jabatan ".header_sort(1));
$table->SetCellAttribute( $row, 4, "width", round((($width-$optWidth)/$totalColums)) );
$table->setCellContent($row,4,"profil_nama ".header_sort(2));
$table->SetCellAttribute( $row, 5, "width", round((($width-$optWidth)/$totalColums)) );
$table->setCellContent($row,5,"profil_tempatlahir ".header_sort(3));
$table->SetCellAttribute( $row, 6, "width", round((($width-$optWidth)/$totalColums)) );
$table->setCellContent($row,6,"profil_tgllahir ".header_sort(4));
$table->SetCellAttribute( $row, 7, "width", round((($width-$optWidth)/$totalColums)) );
$table->setCellContent($row,7,"profil_alamat ".header_sort(5));
$table->SetCellAttribute( $row, 8, "width", round((($width-$optWidth)/$totalColums)) );
$table->setCellContent($row,8,"profil_email ".header_sort(6));
$table->SetCellAttribute( $row, 9, "width", round((($width-$optWidth)/$totalColums)) );
$table->setCellContent($row,9,"profil_homepage ".header_sort(7));
$table->SetCellAttribute( $row, 10, "width", round((($width-$optWidth)/$totalColums)) );
$table->setCellContent($row,10,"profil_ket ".header_sort(8));
$table->SetCellAttribute( $row, 11, "width", round((($width-$optWidth)/$totalColums)) );
$table->setCellContent($row,11,"profil_photo ".header_sort(9));
$table->SetCellAttribute( $row, 12, "width", round((($width-$optWidth)/$totalColums)) );
$table->setCellContent($row,12,"Status ".header_sort(9));
/* one column preserved for edit/delete button */ 
$table->SetCellAttribute( $row, ($totalColums+$optColums), "width", "50" );
$table->setCellContent($row,($totalColums+$optColums) ,"&nbsp;");
$table->SetFancyRowStyle( $row, array("bgcolor" => "white", 'style' => 'color: black',"align"=>"center" ) );
$table->SetFancyRowStyle( $row,array("class"=>"labelTable"));
/* adding row for data  cell */
while($content=mysql_fetch_array($query_page)){
	 $row = $table->AddRow();
	 $table->SetFancyRowStyle( $row,array("class"=>"cellTable"));
/* set cell by record number */
	 $number_page++;
	 $table->SetCellAttribute($row, 1, "width", "30" );
	 $table->SetCellContent( $row, 1, $number_page);
/* set cell by record data */ 
	 $table->SetCellAttribute( $row, 2, "width", round((($width-$optWidth)/$totalColums)) );
	 $table->SetCellContent( $row, 2, ($content["profil_id"]!=""?$content["profil_id"]:"&nbsp; ") );
	 $table->SetCellAttribute( $row, 3, "width", round((($width-$optWidth)/$totalColums)) );
	 $table->SetCellContent( $row, 3, ($content["profil_jabatan"]!=""?$content["profil_jabatan"]:"&nbsp; ") );
	 $table->SetCellAttribute( $row, 4, "width", round((($width-$optWidth)/$totalColums)) );
	 $table->SetCellContent( $row, 4, ($content["profil_nama"]!=""?$content["profil_nama"]:"&nbsp; ") );
	 $table->SetCellAttribute( $row, 5, "width", round((($width-$optWidth)/$totalColums)) );
	 $table->SetCellContent( $row, 5, ($content["profil_tempatlahir"]!=""?$content["profil_tempatlahir"]:"&nbsp; ") );
	 $table->SetCellAttribute( $row, 6, "width", round((($width-$optWidth)/$totalColums)) );
	 $table->SetCellContent( $row, 6, ($content["profil_tgllahir"]!=""?$content["profil_tgllahir"]:"&nbsp; ") );
	 $table->SetCellAttribute( $row, 7, "width", round((($width-$optWidth)/$totalColums)) );
	 $table->SetCellContent( $row, 7, ($content["profil_alamat"]!=""?$content["profil_alamat"]:"&nbsp; ") );
	 $table->SetCellAttribute( $row, 8, "width", round((($width-$optWidth)/$totalColums)) );
	 $table->SetCellContent( $row, 8, ($content["profil_email"]!=""?$content["profil_email"]:"&nbsp; ") );
	 $table->SetCellAttribute( $row, 9, "width", round((($width-$optWidth)/$totalColums)) );
	 $table->SetCellContent( $row, 9, ($content["profil_homepage"]!=""?$content["profil_homepage"]:"&nbsp; ") );
	 $table->SetCellAttribute( $row, 10, "width", round((($width-$optWidth)/$totalColums)) );
	 $table->SetCellContent( $row, 10, ($content["profil_ket"]!=""?$content["profil_ket"]:"&nbsp; ") );
	 $table->SetCellAttribute( $row, 11, "width", round((($width-$optWidth)/$totalColums)) );
	 $table->SetCellContent( $row, 11, ($content["profil_photo"]!=""?"<img width=80% src='../../".$content["profil_photo"]."'>":"&nbsp; ") );
	 $table->SetCellAttribute( $row, 12, "width", round((($width-$optWidth)/$totalColums)) );
	 $table->SetCellContent( $row, 12, ($content["profil_photo"]!=""?$stat[$content["profil_status"]]:"&nbsp; ") );
/* set cell by control button */ 
	 $table->SetCellAttributes( $row, $totalColums+2, array("width"=>"50","nowrap"=>true) );
	 $table->SetCellContent( $row, $totalColums+2 , editButton($content[0]));
}
/* Add row for info page */ 
$row=$table->AddRow();
$table->SetCellColSpan( $row, 1,($totalColums+$optColums) );
$table->SetCellAttributes( $row, 1, array("align"=>"left","width"=>"100%","class"=>"fieldTable") );
$table->SetCellContent( $row, 1, $page->getInfoPage()."<br>".$page->getPaging());
/*  set double color cross rows */ 
$table->set2RowColors( "white", "#eeeeee", 3, $row );
$table->PrintTable();
?>
</form>
</body></html>